package demo.database.MariaDB.D03_元数据;


import javax.sql.DataSource;

import com.titan.core.utils.db.DataSourceUtils;
import com.titan.core.utils.db.JdbcUtils;
import com.titan.core.utils.debug.Timer;
import com.titan.core.utils.io.ConsoleUtils;
import com.titan.core.utils.object.ListSet;
import com.titan.core.web.utils.SpringBootUtils;
import com.titan.services.Container.v1.ContainerUtils;
import com.titan.services.Container.v1.JdbcV1Container.DatabaseMetaDataContainer;
import com.titan.services.to.v1.ToUtils;

import demo.database.MariaDB.utils.MariaDBUtils;

public class D03_列表输出Schema {
    private static void run(final DatabaseMetaDataContainer meta) throws Exception {
        ConsoleUtils.log(meta);
        ListSet<String> schemas = meta.listSchemas();
        for (int i = 0; i < schemas.size(); i++) {
            ConsoleUtils.log(ToUtils.to2Digit(i), schemas.get(i));
        }
    }

    
    public static void main(String[] args) {
        Timer timer = Timer.$();
        DataSource datasource = MariaDBUtils.getDataSource();
        DatabaseMetaDataContainer container = null;
        try {
            JdbcUtils.setDataSource(datasource);
            container = JdbcUtils.getMetaDataDatabase("jdbc.DatabaseMetaData");
            container.startup();
            run(container);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            ContainerUtils.shutdown(container);
            DataSourceUtils.close(datasource);
            SpringBootUtils.shutdown();
            timer.print();
        }
    }
}
